package com.HeJing.实例变量赋值过程_JavaBean_UML类图.方法的相关应用.方法的值传递机制剖析;

/**
 * ClassName: ValueTransferTest
 * Package: com.HeJing.方法的相关应用.方法的值传递机制剖析
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-03-22 19:25
 * @Version: 1.0
 */
public class ValueTransferTest {
    public static void main(String[] args) {
        // 1、基本数据类型的局部变量, 传递的是数据值
        int m = 10;
        int n = m;
        System.out.println("m = " + m + " n = " + n);  // m = 10 n = 10
        m++;
        System.out.println("m = " + m + " n = " + n);  // m = 11 n = 10

        System.out.println("\n*********************************************\n");

        // 2、引用数据类型的局部变量
        // 2.1 数组类型
        int[] arr1 = new int[]{1, 2, 3, 4, 5};
        int[] arr2 = arr1;
        myPrint(arr1);
        myPrint(arr2);
        arr1[0] = 1024;
        myPrint(arr1);
        myPrint(arr2);

        System.out.println("\n*********************************************\n");

        // 2.2对象类型
        Order order1 = new Order();
        order1.orderId = 1001;
        Order order2 = order1;
        order2.orderId = 1002;
        System.out.println(order1.orderId);  // 1002




    }

    // 打印数组的方法定义:
    public static void myPrint(int[] arr) {
        for(int i = 0; i < arr.length - 1; i++) {
            System.out.print(arr[i] + "\t");
        }
        System.out.println(arr[arr.length - 1]);
    }
}































